#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=100005;

int n,k;
vector<int> edges[N];
int fath[N],h[N];
int depth[N];

int h1=0,h2=0;
int p1=1,p2=1;
void dfs(int s){
	bool tag=false;
	for(auto u:edges[s]){
		if(u!=fath[s]){
			tag=true;
			fath[u]=s;
			h[u]=h[s]+1;
			dfs(u);
		}
	}
	//leaf
	if(!tag){
		if(h[s]>=h1){
			h2=h1;p2=p1;
			h1=h[s];p1=s;
		}
		else if(h[s]>=h2){
			h2=h[s];p2=s;
		}
	}
}
void dfs2(int s){
	bool tag=false;
	for(auto u:edges[s]){
		if(u!=fath[s]){
			tag=true;
			fath[u]=s;
			h[u]=h[s]+1;
			dfs2(u);
			depth[s]=depth[u];
		}
	}
	//leaf
	if(!tag){
		depth[s]=h[s];
	}
}

int main(){
	scanf("%d%d",&n,&k);
	int s,t;
	for(int i=0;i<n-1;i++){
		scanf("%d%d",&s,&t);
		edges[s].emplace_back(t);
		edges[t].emplace_back(s);
	}
	fath[1]=0;h[1]=0;
	dfs(1);
	//printf("%d:%d %d:%d\n",p1,h1,p2,h2);
	//
	int len1=0,len2=h1+h2;
	while(len1<len2){
		p1=fath[p1];
		len1++;
		len2--;
		//printf("p1:%d\n",p1);
	}
	int root=p1;
	//printf("root:%d\n",root);
	//rebuild
	fath[root]=0;h[root]=0;
	dfs2(root);
	int g[N];
	for(int i=1;i<=n;i++){
		//printf("%d %d %d ",i,depth[i],h[i]);
		g[i]=depth[i]-h[i];
		//printf("%d\n",g[i]);
	}
	sort(g+1,g+n+1);
	if(g[n-k+1]==g[n-k]){
		printf("%d",g[n-k+1]+1);
	}
	else printf("%d",g[n-k+1]);
	return 0;
}
/*
5 2
1 2
2 3
3 4
4 5
*/
